﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.DataViz.NetworkDiagram.QueryControls
{
    /// <summary>
    /// 
    /// </summary>
    public partial class DateBetweenFilter : UserControl, IFieldFilter
    {
        /// <summary>
        /// 
        /// </summary>
        public DateBetweenFilter()
        {
            InitializeComponent();
        }

        private void DateBetweenFilter_Load(object sender, EventArgs e)
        {
            if(this.Stat !=null && this.Stat.DataType==SimpleDataType.DateTimeType)
            {
                this.lbl_FieldName.Text = this.Stat.FieldName;
                this.dateFrom.Value = (DateTime) this.Stat.MinValue;
                this.dateTo.Value = (DateTime) this.Stat.MaxValue;
            }
        }

        private void dateFrom_ValueChanged(object sender, EventArgs e)
        {
            DateTime fromDate = this.dateFrom.Value;
            DateTime toDate = this.dateTo.Value;
            if (this.FieldFilterUpdated != null)
                this.FieldFilterUpdated(this.NetworkName, this.Stat.FieldName, fromDate, toDate, null);
        }

        private void dateTo_ValueChanged(object sender, EventArgs e)
        {
            DateTime fromDate = this.dateFrom.Value;
            DateTime toDate = this.dateTo.Value;
            if (this.FieldFilterUpdated != null)
                this.FieldFilterUpdated(this.NetworkName, this.Stat.FieldName, fromDate, toDate, null);
        }

        #region Implementation of IFieldFilter

        private FieldStat _Stat;
        /// <summary>
        /// 
        /// </summary>
        public FieldStat Stat
        {
            get
            {
                return _Stat;
            }
            set
            {
                _Stat = value;
            }
        }

        private string _NetworkName;
        /// <summary>
        /// 
        /// </summary>
        public string NetworkName
        {
            get
            {
                return _NetworkName;
            }
            set
            {
                _NetworkName = value;
            }
        }

        public event OnFieldFilterUpdated FieldFilterUpdated;

        #endregion
    }
}
